﻿
##################
# Foreign Affairs
##################

# Foreign Affairs opinion base modifier
chancellor_foreign_affairs_opinion_base = {
	add = diplomacy
	divide = 2
}

# Bonus to opinion from Adaptive Traditions
chancellor_foreign_affairs_opinion_max_perk_bonus_modifier = {
	add = chancellor_foreign_affairs_opinion_base
	multiply = {
		add = adaptive_traditions_perk_impact_percent
		divide = 100
	}
}

#chancellor_foreign_affairs_opinion_max_perk_bonus_modifier = {
#	value = 0
#	if = {
#		limit = {
#			scope:councillor_liege = { has_perk = adaptive_traditions_perk }
#		}
#		add = chancellor_foreign_affairs_opinion_base
#		multiply = {
#			add = adaptive_traditions_perk_impact_percent
#			divide = 100
#		}
#	}
#}

# Bonus to opinion from Bureaucrats
chancellor_foreign_affairs_opinion_max_erudition_modifier = {
	add = chancellor_foreign_affairs_opinion_base
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

# Calculated max opinion
chancellor_foreign_affairs_opinion_max = {
	add = chancellor_foreign_affairs_opinion_base
	# Add bonus from Clerical Justification:
	if = {
		limit = {
			scope:councillor_liege = { has_perk = adaptive_traditions_perk }
		}
		add = chancellor_foreign_affairs_opinion_max_perk_bonus_modifier
	}
	# Add bonus from Bureaucrats
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		add = chancellor_foreign_affairs_opinion_max_erudition_modifier
	}
}

# Set to max for AI, or gradual scale for players
chancellor_foreign_affairs_realm_opinion_scale = {
	add = 0
	if = {
		limit = {
			is_ai = yes
			scope:councillor_liege = { is_independent_ruler = no }
		}
		add = chancellor_foreign_affairs_opinion_max
	}
	else_if = {
		limit = {
			has_variable = chancellor_foreign_affairs_opinion_value
			scope:councillor_liege = { is_independent_ruler = no }
		}
		add = liege.var:chancellor_foreign_affairs_opinion_value
	}
}

chancellor_foreign_affairs_independent_opinion_scale = {
	add = 0
	if = {
		limit = {
			scope:councillor_liege = {
				is_ai = yes
				is_independent_ruler = yes
			}
		}
		add = chancellor_foreign_affairs_opinion_max
	}
	else_if = {
		limit = {
			scope:councillor_liege = {
				is_independent_ruler = yes
				has_variable = chancellor_foreign_affairs_opinion_value
			}
		}
		add = liege.var:chancellor_foreign_affairs_opinion_value
	}
}

# Calculate monthly increase
chancellor_foreign_affairs_monthly_increase = {
	add = chancellor_foreign_affairs_opinion_max
	divide = 24
}

### Prestige gain

# Base prestige gain scale
chancellor_foreign_affairs_prestige_gain_base = {
	add = diplomacy
	divide = 20
}

# Adaptive Traditions bonus
chancellor_foreign_affairs_prestige_gain_perk_bonus_scale = {
	if = {
		limit = { scope:councillor_liege = { has_perk = adaptive_traditions_perk } }
		add = chancellor_foreign_affairs_prestige_gain_base
		multiply = {
			value = adaptive_traditions_perk_impact_percent
			divide = 100
		}
	}
}

# Bureaucrats bonus
chancellor_foreign_affairs_prestige_gain_erudition_modifier = {
	if = {
		limit = {
			exists = scope:councillor_liege.dynasty
			scope:councillor_liege.dynasty = { has_dynasty_perk = erudition_legacy_5 }
		}
		add = chancellor_foreign_affairs_prestige_gain_base
		multiply = {
			add = erudition_legacy_5_percentage
			divide = 100
		}
	}
}

# Final calculation (used for tooltips only)
chancellor_foreign_affairs_prestige_calculation = {
	add = {
		value = chancellor_foreign_affairs_prestige_gain_base
		desc = "Base value"
	}
	add = {
		value = chancellor_foreign_affairs_prestige_gain_perk_bonus_scale
		desc = "Perk bonus"
	}
	add = {
		value = chancellor_foreign_affairs_prestige_gain_erudition_modifier
		desc = "Legacy bonus"
	}
}



####################
# Domestic Affairs
####################
chancellor_domestic_affairs_opinion_base = {
	add = diplomacy
	divide = 2
}

chancellor_domestic_affairs_opinion_chains_of_loyalty_bonus = {
	add = chancellor_domestic_affairs_opinion_base
	multiply = {
		add = chains_of_loyalty_percentage
		divide = 100
	}
}

chancellor_domestic_affairs_opinion_erudition_bonus = {
	add = chancellor_domestic_affairs_opinion_base
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

chancellor_domestic_affairs_opinion_max = {
	add = diplomacy
	if = {
		limit = {
			scope:councillor_liege = { has_perk = chains_of_loyalty_perk }
		}
		add = chancellor_domestic_affairs_opinion_chains_of_loyalty_bonus
	}
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		add = chancellor_domestic_affairs_opinion_erudition_bonus
	}
	divide = 2
}

chancellor_domestic_affairs_opinion_scale = {
	value = 0
	if = {
		limit = {
		    scope:councillor_liege = {
		        is_ai = yes
		        is_independent_ruler = yes
		    }
		}
		add = chancellor_domestic_affairs_opinion_max
	}
	else_if = {
		limit = {
			scope:councillor_liege = { has_variable = chancellor_domestic_affairs_opinion_value }
		}
		add = scope:councillor_liege.var:chancellor_domestic_affairs_opinion_value
	}
}

chancellor_domestic_affairs_monthly_increase = {
	add = chancellor_domestic_affairs_opinion_max
	divide = 24
}

#####################
# Integrate Title
#####################

chancellor_integrate_title_current_progress = {
	value = 0
	if = {
		limit = { exists = scope:county }
		add = scope:county.active_de_jure_drift_progress
	}
}

chancellor_integrate_title_progress_gain = {
	add = diplomacy
	multiply = 0.1
}

chancellor_integrate_title_erudition_bonus = {
	add = chancellor_integrate_title_progress_gain
	multiply = erudition_legacy_5_percentage
	divide = 100
}

# Relation impact
chancellor_integrate_title_monthly_increase_friend_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_best_friend_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_rival_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_nemesis_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}



### Learn on the Job modifier
chancellor_learn_on_the_job_scale = {
	value = 0
	if = {
		limit = {
			liege = { has_perk = learn_on_the_job_perk }
		}
		add = diplomacy
		multiply = {
			add = learn_on_the_job_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}
